package com.gitee.base.modules.core.dao;

import com.gitee.base.modules.core.model.SysUserLoginLog;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * 随便写写统计
 */
public interface SysUserLoginLogMapper extends BaseMapper<SysUserLoginLog> {

    @Select("<script>" +
            "SELECT DATE_FORMAT(a.time,'%Y-%m-%d') AS `date`,COUNT(1) AS `count` FROM sys_user_login_log a WHERE DATE_FORMAT(a.time,'%Y-%m-%d') IN" +
            "<foreach item='item' index='index' collection='dateList' open='(' separator=',' close=')'>" +
            "#{item}" +
            "</foreach>" +
            "GROUP BY `date`" +
            "</script>")
    List<Map<String,Object>> countUserLoginLogByDateList(@Param("dateList") List<String> dateList);

    @Select(value = "SELECT a.os AS `name`,COUNT(a.os) AS `value` FROM sys_user_login_log a WHERE a.time>=#{start} and a.time<=#{end} GROUP BY a.os")
    List<Map<String,Object>> countUserLoginOsByDateRange(@Param("start") LocalDateTime start, @Param("end") LocalDateTime end);

    @Select(value = "SELECT a.browser_short AS `name`,COUNT(a.os) AS `value` FROM sys_user_login_log a WHERE a.time>=#{start} and a.time<=#{end} GROUP BY a.browser")
    List<Map<String,Object>> countUserLoginBrowerByDateRange(@Param("start") LocalDateTime start, @Param("end") LocalDateTime end);
}
